﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Wpf.Telemetry.Service.Model;
using System.Web.Services.Protocols;
using System.Diagnostics;
using Wpf.Telemetry.Service.DataAccess;
using Wpf.Telemetry.Service.DataAccess.SQLite;
using sql = Wpf.Telemetry.Service.DataAccess.SQLServer;
using System.Web.Configuration;


namespace Wpf.Telemetry.Service
{
    /// <summary>
    /// Summary description for Telemetry
    /// </summary>
    [WebService(Namespace = "http://LearnWPF.com/Telemetry/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Telemetry : System.Web.Services.WebService
    {
        // use can use config to drive which one is created, write a factory, a factory factory, a factory factory factory etc.
        ITelemetryRecorder recorder = new SQLiteTelemetryRecorder(WebConfigurationManager.ConnectionStrings["Telemetry.SQLite"].ConnectionString);
        //ITelemetryRecorder recorder = new sql.SQLTelemetryRecorder(WebConfigurationManager.ConnectionStrings["Telemetry.SQLServer"].ConnectionString);

        [WebMethod]
        [SoapDocumentMethod(OneWay=true)]
        public void ReportFeatureUsage(ApplicationInformation appInfo, SystemInformation systemInfo, List<FeatureUsage> featureUsage)
        {
            recorder.SaveFeatureUsage(appInfo, systemInfo, featureUsage);
        }

        [WebMethod]
        [SoapDocumentMethod(OneWay = true)]
        public void ReportException(SystemInformation systemInfo, ExceptionInformation exceptionInfo)
        {
            recorder.SaveException(systemInfo, exceptionInfo);
        }
    }
}
